/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __K_PROFILE_H__
#define __K_PROFILE_H__

/* includes (standard library, system) ---------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
/* includes (local) ----------------------------------------------------------*/
#include "k_task.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/

struct profile_data {
    task_id task; /* NULL if system */
    bool tsc_started;
    unsigned long tsc_start;
    /* timestamp accumulator */
    unsigned long long tsc_all;
};

/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

extern void profile_sys_enter(void);
extern void profile_sys_exit(void);
extern void profile_task_enter(task_id);
extern int profile_start(void);
extern int profile_foreach(void (*callback)(struct profile_data *, uintptr_t), uintptr_t arg);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __K_PROFILE_H__ */
